<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="com.kaifamiao.jsp.entity.Customer" %>
<%@ page import="java.util.List" %>

<%
    // 登录时在会话中设置的属性名是什么这里就根据什么获取
    Object x = session.getAttribute( "customer" );
%>

<html>
  <head>
      <title>列表</title>
      <style type="text/css">
          table { margin: auto ; width: 80vw ; border-collapse: collapse ; }
          td { text-align: center ; }
          tr:nth-child(2n) { background: #dfdfdf ; }
          tr:nth-child(2n+1) { background: #fcfcd6 ; }
          h3 , p { text-align: center ; }
      </style>
  </head>
  <body>

    <h3>客户列表</h3>

    <p>${ message }</p>
    <% session.removeAttribute( "message" ); %>

    <table>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>出生日期</th>
            <th>用户名</th>
            <th>昵称</th>
            <% if( x instanceof Customer ) { %>
            <th>操作</th>
            <% } %>
        </tr>

        <%
        List<Customer> list = (List<Customer>)request.getAttribute( "customers" );
        for (int i = 0; i < list.size() ; i++) {
            Customer c = list.get( i );
        %>
            <tr>
                <td> <%= c.getId() %> </td>
                <td> <%= c.getName() %> </td>
                <td> <%= c.getGender() %> </td>
                <td> <%= c.getBirthdate() %> </td>
                <td> <%= c.getUsername() %> </td>
                <td> <%= c.getNickname() %> </td>
                <% if( x instanceof Customer ) { %>
                <td>
                    <a href="${pageContext.request.contextPath}/customer/edit?id=<%= c.getId() %>">编辑</a>
                    <a href="${pageContext.request.contextPath}/customer/remove?id=<%= c.getId() %>">删除</a>
                </td>
                <% } %>
            </tr>
        <%
        }
        %>
    </table>


    <p>
        <a href="${pageContext.request.contextPath}/sign-in.jsp">登录</a>
        |
        <a href="${pageContext.request.contextPath}/sign-up.jsp">注册</a>
    </p>

  </body>
</html>
